﻿var SearchController = {
	
	$keywords: $('#sole-input'),	
	$cancel: $(".input-clear"),
		
	initial: function() {
		SearchController.$keywords.focus();
		SearchController.$keywords.val('');
		
		SearchController.onKeyPress();
	},
	
	onClick: function() {
		SearchController.$keywords.click(function(){
			if($(this).val()==""){
				ItemController.showItemBox();
			}
		});
	},
	
	onKeyPress: function() {
		SearchController.$keywords.on('keypress', function(e) {
	        if (e.which === 13) {
				EMarkerList.reRenderData();
	            
	            SearchController.setValue(EMarkerList.$keywords.val());
	    		SearchController.showCancelIcon();
	    		ItemController.hideItemBox();
	    		ConditionController.showOuterBox();
	    		ConditionController.changeShowStatus("enterprise");
	    		ConditionController.render();
	    		PanelController.showPanel();
	        }
	    });
	},
	
	onCancelIconClick: function() {
		SearchController.$cancel.click(function(){
			SearchController.onCancelIconClear();
		});
	},
	
	showCancelIcon: function() {
		SearchController.$cancel.css({"display":"block"});
	},
	
	hideCancelIcon:function(){
		SearchController.$cancel.css({"display":"none"});
	},
	
	onCancelIconClear: function() {
		SearchController.hideCancelIcon();
		SearchController.initial();
		ItemController.initial();
		ConditionController.initial();
		PanelController.initial();
		AreaLevelController.initial();
		TradeLevelController.initial();
		ControlLevelController.initial();
		AdvancedController.initial();
		
		//清空markerList及地图
		clearAllMarkerList();
	},
	
	setValue: function(val){
		SearchController.$keywords.val(val);
	}
};


var ItemController = {
	
	itemMap : {
		'enterprise' : '排污许可企业',
		'emission' : '排放量',
		'warm' : '许可证到期预警',
		'illegal' : '违法企业',
		'envriornment' : '环境与排放量',
		'point' : '排污口'
	},
		
	initial: function(){
		ItemController.hideItemBox();
	},
		
	showItemBox: function() {
		$("#aroundbox").css({"display":"block"});
		$("#aroundbox").slideDown(100);
	},
	
	hideItemBox: function() {
		$("#aroundbox").css({"display":"none"});
	},
	
	onItemChange: function() {
		$('.item').each(function(){
			$(this).click(function(){
				var item = $(this).attr('keyword');
				ItemController.onItemSelect(item);
			});
		});
	},
	
	onItemSelect: function (item) {
		SearchController.setValue(ItemController.itemMap[item]?ItemController.itemMap[item]:item);
		SearchController.showCancelIcon();
		ItemController.hideItemBox();
		ConditionController.showOuterBox();
		ConditionController.changeShowStatus(item);
		ConditionController.render();
		PanelController.showPanel();
		
		if(item=='enterprise') {
			EMarkerList.load();
		}else if(item=='emission'){
			ESMarkerList.load();
		}else if(item=='warm'){
			LMarkerList.load();
		}else if(item=='illegal'){
			
		}else if(item=='envriornment'){
			
		}else if(item=='point'){
			PMarkerList.load();
		}
	}
};

var ConditionController = {
	
	typeData: {   
		list:[  
			{"itemFlag":"bussiness_enterprise_flag=1;bussiness_point_flag=1","queryType":"area","bussinessName":"广西","class":"cl-area","ShowStatus":true},  
			{"itemFlag":"bussiness_enterprise_flag=1;bussiness_point_flag=1","queryType":"trade","bussinessName":"全部行业","class":"cl-trade","ShowStatus":true} ,
			{"itemFlag":"bussiness_enterprise_flag=1","queryType":"type","bussinessName":"监管类型","class":"cl-type","ShowStatus":true},  
			{"itemFlag":"bussiness_point_flag=1;","queryType":"gasWaterType","bussinessName":"排污类型","class":"cl-type cl-ptype","ShowStatus":false},
			{"itemFlag":"bussiness_enterprise_flag=1;=1;terprise","queryType":"sort","bussinessName":"其它筛选","class":"cl-sort","ShowStatus":true},  
			{"itemFlag":"bussiness_warm_flag=1;bussiness_emission_flag=1;bussiness_illegal_flag=1;bussiness_envriornment_flag=1","queryType":"year","bussinessName":"年份","class":"cl-sort cl-year","ShowStatus":false},
			{"itemFlag":"bussiness_emission_flag=1;bussiness_envriornment_flag=1","queryType":"permitActual","bussinessName":"许可/实际排放量","class":"cl-sort","ShowStatus":false},
			{"itemFlag":"bussiness_envriornment_flag=1;","queryType":"air","bussinessName":"空气指标","class":"cl-sort cl-air","ShowStatus":false}
		]  
	},
	
	changeShowStatus: function(itemKey){
		for(var i=0; i<ConditionController.typeData.list.length; i++) {
			var d = ConditionController.typeData.list[i];
			if(d["itemFlag"].indexOf(itemKey)!=-1 || d["itemFlag"].indexOf("all")!=-1) {
				d["ShowStatus"] = true;
			}else {
				d["ShowStatus"] = false;
			}
			
		}
	},
	
	render: function() {
		AMapUI.loadUI(['misc/MarkerList'], function(MarkerList) {
			var typeList = '<% for(var i=0;i < data.length;i++) { %>'+  
								'<% if(data[i].ShowStatus) { %>'+
								'<em class="<%- data[i].class %>" data-val="query_type=<%- data[i].queryType %>" data-spm-anchor-id="" style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(224, 224, 224);">'+
									'<span data-spm-anchor-id="">'+
										'<%- data[i].bussinessName %>'+
									'</span>'+
									'<span class="caret">'+
									'</span>'+
								'</em>'+
								'<% } %>'+
							 '<% } %>';
			var html = MarkerList.utils.template(typeList, {data: ConditionController.typeData.list});  
			$("#content").html("").html(html); 
			ConditionController.onSelect();
		});
	},
		
	initial: function(){
		ConditionController.hideOuterBox();
		ConditionController.hideConditionList();
	},	
		
	onSelect: function (item) {
		$("p>em").each(function(){
			$(this).click(function(){
				var val = $(this).attr('data-val');
				ConditionController.triggerToggle(val.split("=")[1]);
				/*if(queryType[val] && typeof queryType[val]==='function') {
					queryType[val]();
				}*/
			});
		});
	},
	
	triggerToggle: function(id) {
		$(".classsify-down").not("#"+id).css({"display":"none"});
		$("#"+id).slideToggle(200);
	},
	
	hideOuterBox: function(){
		$(".classify").css({"display":"none"});
	},
	
	showOuterBox: function(){
		$(".classify").css({"display":"block"});
	},
	
	showConditionList: function(){
		$(".classsify-down").css({"display":"none"});
	},
	
	hideConditionList: function(){
		$(".classsify-down").css({"display":"none"});
	}
};

var AreaLevelController = {
	
	initial: function(){
		$("em.cl-area>span").first().text('广西');
	},	
	
	render: function(data) {
		AMapUI.loadUI(['misc/MarkerList'], function(MarkerList) {
			//area-level1-select
			var province = 	 '<li id="cl-9999" class="area-level1-select">'+
								'<span class="cl-area-name">'+
								'广西' +
								'</span>'+
								'<span class="cl-right-arrow">'+
								'</span>'+
							 '</li>';
			var areaLevel1List = '<% for(var i=0;i < data.length;i++) { %>'+ 
									 '<% if(i==0) { %>' +
									 '<li id="cl-<%- i %>" class="area-level1-select">'+
										'<span class="cl-area-name">'+
										'<%- data[i].regionname %>' +
										'</span>'+
										'<span class="cl-right-arrow">'+
										'</span>'+
									 '</li>'+
									 '<% } %>'+
									 '<% if(i>0) { %>' +
									 '<li id="cl-<%- i %>" class="">'+
										'<span class="cl-area-name">'+
										'<%- data[i].regionname %>' +
										'</span>'+
										'<span class="cl-right-arrow">'+
										'</span>'+
									 '</li>'+
									 '<% } %>'+
								 '<% } %>';
			//area-level2-select
			var province2List =  '<ul class="classify-area-level2" cl_num="9999" style="flex: 2 1 0%;">'+
									 '<li data-val="business_area_flag=1;adcode='+data.codeRegion+';custom=business_area:广西">'+
										'全省'+
									 '</li>'+
								 '</ul>';
			var areaLevel2List = '<% for(var i=0;i < data.length;i++) { %>'+ 
								 '<ul class="classify-area-level2" cl_num="<%- i %>" style="flex: 2 1 0%;">'+
									 '<li data-val="business_area_flag=1;adcode=<%- data[i].codeRegion %>;custom=business_area:<%- data[i].regionname %>">'+
										''+'全市'+
									 '</li>'+
									 '<% for(var j=0;j < data[i].children.length;j++) { %>'+ 
									 '<li data-val="business_area_flag=1;adcode=<%- data[i].children[j].codeRegion %>;custom=business_area:<%- data[i].children[j].regionname %>">'+
										''+'<%- data[i].children[j].regionname %>'+
									 '</li>'+
									 '<% } %>'+
								 '</ul>'+
								 '<% } %>';
			var html = 	'<ul class="classify-area-level1">' + 
							province+
							MarkerList.utils.template(areaLevel1List, {data: data.children}) + 
						'</ul>';
			html += (province2List+MarkerList.utils.template(areaLevel2List, {data: data.children}));
			
			$("#area").html(html); 
			
			AreaLevelController.onLevel1Select();
			AreaLevelController.onLevel2Select();
		});
	},
	
	onLevel1Select: function(item) {
		$('#area ul.classify-area-level1 li').each(function(){
			$(this).mouseover(function(){
				$('#area ul.classify-area-level1 li').removeClass('area-level1-select');
				$(this).addClass('area-level1-select');
				var c = $(this).attr('id');
				if(c && c.split('-').length==2) {
					var id = c.split('-')[1];
					$('#area .classify-area-level2').css({"display":"none"});
					$('#area .classify-area-level2').each(function(){
						if($(this).attr('cl_num')==id) {
							$(this).css({"display":"block"});
						}
					});
				}
			});
		});
	},

	onLevel2Select: function(item) {
		$('#area ul.classify-area-level2 li').each(function(){
			$(this).click(function(){
				var val = $(this).attr('data-val');
				var $span = $("em.cl-area>span").first();
				var s = val.split(";");
				if($(this).text()=='全部' || $(this).text()=='全省' || $(this).text()=='全市') {
					if(s && s.length>0){
						$span.text(s[2].split(":")[1]);
						AreaLevelController.setAreaCode($span, s[1].split("=")[1]);
					}
				}else {
					$span.text($(this).text());
					AreaLevelController.setAreaCode($span, s[1].split("=")[1]);
				}
				$('#area ul.classify-area-level2 li').removeClass("area-level2-select");
				$(this).addClass("area-level2-select");
				ConditionController.hideConditionList();
				
				//todo：enterprise
				EMarkerList.reRenderData();
			});
		});
	},
	
	setAreaCode:function($span, code){
		$span.attr('data-spm-anchor-id', code);
	},
	
	getAreaCode:function(){
		var $span = $("em.cl-area>span").first();
		return $span.attr('data-spm-anchor-id');
	}
};

var TradeLevelController = {
	
	initial: function(){
		$("em.cl-trade>span").first().text("全部行业");
	},	
	
	subTradeName: function(name, len){
		if(name&&name.length>len){
			return name.substring(0,len);
		}
		return name;
	},
	
	render: function(data) {
		
		AMapUI.loadUI(['misc/MarkerList'], function(MarkerList) {
			//area-level1-select
			var province = 	 '<li id="cl-9999" class="area-level1-select">'+
								'<span class="cl-area-name">'+
								'全部行业' +
								'</span>'+
								'<span class="cl-right-arrow">'+
								'</span>'+
							 '</li>';
			var tradeLevel1List = '<% for(var i=0;i < data.length;i++) { %>'+ 
									 '<% if(i==0) { %>' +
									 '<li id="cl-<%- i %>" class="area-level1-select" title="<%- data[i].tradeName%>">'+
										'<span class="cl-area-name">'+
										'<%- TradeLevelController.subTradeName(data[i].tradeName, 5) %>' +
										'</span>'+
										'<span class="cl-right-arrow">'+
										'</span>'+
									 '</li>'+
									 '<% } %>'+
									 '<% if(i>0) { %>' +
									 '<li id="cl-<%- i %>" class="" title="<%- data[i].tradeName%>">'+
										'<span class="cl-area-name">'+
										'<%- TradeLevelController.subTradeName(data[i].tradeName, 5) %>' +
										'</span>'+
										'<span class="cl-right-arrow">'+
										'</span>'+
									 '</li>'+
									 '<% } %>'+
								 '<% } %>';
			//area-level2-select
			var province2List =  '<ul class="classify-area-level2" cl_num="9999" style="flex: 2 1 0%;">'+
									 '<li data-val="business_area_flag=1;adcode=;custom=business_area:全部行业">'+
										'全部'+
									 '</li>'+
								 '</ul>';
			var tradeLevel2List = '<% for(var i=0;i < data.length;i++) { %>'+ 
								  '<ul class="classify-area-level2" cl_num="<%- i %>" style="flex: 2 1 0%;">'+
									 '<li data-val="business_area_flag=1;codeTrade=<%- data[i].codeTrade %>;custom=business_area:<%- TradeLevelController.subTradeName(data[i].tradeName, 5) %>">'+
										''+'全部'+
									 '</li>'+
									 '<% for(var j=0;j < data[i].children.length;j++) { %>'+ 
									 '<li title="<%- data[i].children[j].tradeName %>" data-val="business_area_flag=1;adcode=<%- data[i].children[j].codeTrade %>;custom=business_area:<%- data[i].children[j].tradeName %>">'+
										''+'<%- TradeLevelController.subTradeName(data[i].children[j].tradeName, 4) %>'+
									 '</li>'+
									 '<% } %>'+
								  '</ul>'+
								  '<% } %>';
			var html = 	'<ul class="classify-area-level1">' + 
							province+
							MarkerList.utils.template(tradeLevel1List, {data: data}) + 
						'</ul>';
			html += (province2List+MarkerList.utils.template(tradeLevel2List, {data: data}));
			
			$("#trade").html(html); 
			
			TradeLevelController.onLevel1Select();
			TradeLevelController.onLevel2Select();
		});
	},
	
	onLevel1Select: function(item) {
		$('#trade ul.classify-area-level1 li').each(function(){
			$(this).mouseover(function(){
				$('#trade ul.classify-area-level1 li').removeClass('area-level1-select');
				$(this).addClass('area-level1-select');
				var c = $(this).attr('id');
				if(c && c.split('-').length==2) {
					var id = c.split('-')[1];
					$('#trade .classify-area-level2').css({"display":"none"});
					$('#trade .classify-area-level2').each(function(){
						if($(this).attr('cl_num')==id) {
							$(this).css({"display":"block"});
						}
					});
				}
			});
		});
	},

	onLevel2Select: function(item) {
		$('#trade ul.classify-area-level2 li').each(function(){
			$(this).click(function(){
				var val = $(this).attr('data-val');
				var s = val.split(";");
				var $span = $("em.cl-trade>span").first();
				if($(this).text()=='全部') {
					if(s && s.length>0){
						$span.text(s[2].split(":")[1]);
						TradeLevelController.setTradeCode($span, s[1].split("=")[1]?s[1].split("=")[1]:'');
					}
				}else {
					$span.text($(this).text());
					TradeLevelController.setTradeCode($span, s[1].split("=")[1]);
				}
				$('#trade ul.classify-area-level2 li').removeClass("area-level2-select");
				$(this).addClass("area-level2-select");
				ConditionController.hideConditionList();
				
				//todo：enterprise
				EMarkerList.reRenderData();
			});
		});
	},
	
	setTradeCode:function($span, code){
		$span.attr('data-spm-anchor-id', code);
	},
	
	getTradeCode:function(){
		var $span =$("em.cl-trade>span").first();
		return $span.attr('data-spm-anchor-id');
	}
};

var ControlLevelController = {
	
	initial: function(){
		$("em.cl-type>span").first().text('监管类型');
	},
	
	render: function(data){
		
		AMapUI.loadUI(['misc/MarkerList'], function(MarkerList) {
			var all = '<li id="cl-0" data-val="business_enterprise_flag=1;code=;custom=business_area:监管类型">'+
							'<span class="cl-area-name">'+
								'全部'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
					  '</li>';
			
			var typeList =  '<% for(var i=0;i < data.length;i++) { %>'+  
								'<li id="cl-<%- i %>" data-val="business_enterprise_flag=1;code=<%- data[i].generalCode %>;custom=business_area:<%- data[i].cateGoryName %>">'+
									'<span class="cl-area-name">'+
										'<%- data[i].cateGoryName %>'+
									'</span>'+
									'<span class="cl-right-arrow">'+
									'</span>'+
								'</li>'+
							'<% } %>';
			var html = '<ul class="classify-sort-type">'+
						all+
						MarkerList.utils.template(typeList, {data: data})+
						'</ul>';  
			$("#type").html("").html(html); 
			$('#type ul.classify-sort-type li').first().addClass('sort-select');
			
			ControlLevelController.onMove();
			ControlLevelController.onSelect();
		});
	},
	
	onMove: function(item) {
		$('#type ul.classify-sort-type li').each(function(){
			$(this).mouseover(function(){
				$('ul.classify-sort-type li').removeClass('sort-select');
				$(this).addClass('sort-select');
			});
		});
	},
	
	onSelect: function(item) {
		$('#type ul.classify-sort-type li').each(function(){
			$(this).click(function(){
				var $span = $("em.cl-type>span").first();
				var val = $(this).attr('data-val');
				var s = val.split(";")
				if($(this).text()=='全部') {
					if(s && s.length>0){
						$span.text(s[2].split(":")[1]);
						ControlLevelController.setControlLevelCode($span, s[1].split("=")[1]?s[1].split("=")[1]:'');
					}
				}else {
					$span.text($(this).text());
					ControlLevelController.setControlLevelCode($span, s[1].split("=")[1]?s[1].split("=")[1]:'');
				}
				$('#type ul.classify-sort-type li').removeClass('sort-select');
				$(this).addClass('sort-select');
				ConditionController.hideConditionList();
				
				//todo：enterprise
				EMarkerList.reRenderData();
			});
		});
	},
	
	setControlLevelCode:function($span, code){
		$span.attr('data-spm-anchor-id', code);
	},
	
	getControlLevelCode:function(){
		var $span =$("em.cl-type>span").first();
		return $span.attr('data-spm-anchor-id');
	}
};

var AdvancedController = {
		
	initial: function(){
		
		$("#myButton").click(function(){
			if(!AdvancedController.validateNumberic($('#permitEmissionFrom')) 
					|| !AdvancedController.validateNumberic($('#permitEmissionTo'))
					|| !AdvancedController.validateNumberic($('#actualEmissionFrom')) 
					|| !AdvancedController.validateNumberic($('#actualEmissionTo'))){
				alert('请填写数字');
				return;
			}
			EMarkerList.reRenderData();
			ConditionController.hideConditionList();
		});
	},
	
	validateNumberic: function($field) {
        var value = $field.val();
        if (value == '') {
            return true;
        }
        return !isNaN(parseFloat(value)) && isFinite(value);
    },
	
	renderPolluteList: function(data) {
		for(var i=0; i<data.length; i++) {
			$("#permitPolluteCode").append("<option value='"+data[i].polluteCode+"'>"+data[i].polluteName+"</option >");
			$("#actualPolluteCode").append("<option value='"+data[i].polluteCode+"'>"+data[i].polluteName+"</option >");
		}
	},
	
	renderYearList: function(diff) {
		var d = new Date().getFullYear();
		for(var i=0; i<diff; i++) {
			$("#startYear").append("<option value='"+(d-i)+"'>"+(d-i)+"年</option >");
			$("#endYear").append("<option value='"+(d-i)+"'>"+(d-i)+"年</option >");
		}
	},
	
	renderProcessTech: function(data) {
		for(var i=0; i<data.length; i++) {
			$("#processTechCheck").append(
				'<label style="margin-right:10px;">'+
					'<input type="checkbox" name="processTechCheckbox" value="'+data[i].techId+'">'+data[i].techName+
				'</label>'
			);
		}
	},
	
	getFormParamsData: function() {
		var param = {};
		
		var s = $('#advForm').serialize();
		var sa = s.split("&");
		if(sa && sa.length>0){
			$.each(sa, function(i, e){
				var kv = e.split('=');
				if(kv && kv.length>0){
					param[kv[0]] = kv[1];
				}
			});
		}
		param.processTechIds="";
		$("input[name='processTechCheckbox']:checked").each(function(){
			param.processTechIds += "," + $(this).val();
		});
		if(param.processTechIds.length>0) {
			param.processTechIds = param.processTechIds.substring(1);
		}
		
		return param;
	}
};

var GasWaterTypeController = {
	
	initial: function(){
		$("em.cl-ptype>span").first().text('排污类型');
		
		GasWaterTypeController.render();
	},
	
	render: function(data){
		
		var html =  '<ul class="classify-sort-type">'+
							'<li id="cl-0" class="sort-select">'+
								'<span class="cl-area-name">'+
									'全部'+
								'</span>'+
								'<span class="cl-right-arrow">'+
								'</span>'+
							'</li>'+
							'<li id="cl-0" class="">'+
								'<span class="cl-area-name">'+
									'废气'+
								'</span>'+
								'<span class="cl-right-arrow">'+
								'</span>'+
							'</li>'+
							'<li id="cl-1" class="">'+
								'<span class="cl-area-name">'+
									'废水'+
								'</span>'+
								'<span class="cl-right-arrow">'+
								'</span>'+
							'</li>'+
					'</ul>';
		$("#gasWaterType").html(html); 
		$('#gasWaterType ul.classify-sort-type li').first().addClass('sort-select');
		
		GasWaterTypeController.onMove();
		GasWaterTypeController.onSelect();
	},
	
	onMove: function(item) {
		$('#gasWaterType ul.classify-sort-type li').each(function(){
			$(this).mouseover(function(){
				$('ul.classify-sort-type li').removeClass('sort-select');
				$(this).addClass('sort-select');
			});
		});
	},
	
	onSelect: function(item) {
		$('#gasWaterType ul.classify-sort-type li').each(function(){
			$(this).click(function(){
				$("em.cl-type>span").first().text($(this).text());
				$('#gasWaterType ul.classify-sort-type li').removeClass('sort-select');
				$(this).addClass('sort-select');
				ConditionController.hideConditionList();
			});
		});
	}
};

var YearController = {
		
	initial: function(){
		$("em.cl-year>span").first().text('年份');
		
		YearController.render(5);
	},
	
	render: function(diff){
		
		var d = new Date().getFullYear();
		var html = '';
		for(var i=0; i<diff; i++){
			html +='<li id="cl-'+i+'" class="" data-val="business_year_flag=1;adcode='+(d-i)+';custom=business_year:'+(d-i)+'年">'+
							'<span class="cl-area-name">'+
							(d-i)+'年'+
						'</span>'+
						'<span class="cl-right-arrow">'+
						'</span>'+
					'</li>'
		}
		html = '<ul class="classify-sort-type">'+ html +'</ul>';
		$("#year").html(html); 
		$('#year ul.classify-sort-type li').first().addClass('sort-select');
		
		YearController.onMove();
		YearController.onSelect();
	},
	
	onMove: function() {
		$('#year ul.classify-sort-type li').each(function(){
			$(this).mouseover(function(){
				$('ul.classify-sort-type li').removeClass('sort-select');
				$(this).addClass('sort-select');
			});
		});
	},
	
	onSelect: function() {
		$('#year ul.classify-sort-type li').each(function(){
			$(this).click(function(){
				var val = $(this).attr('data-val');
				var s = val.split(";")
				var $span = $("em.cl-year>span").first();
				$span.text($(this).text());
				$('#year ul.classify-sort-type li').removeClass('sort-select');
				$(this).addClass('sort-select');
				ConditionController.hideConditionList();
				
				YearController.setYearCode($span, s[1].split("=")[1]?s[1].split("=")[1]:'');
				
				//todo：LMarkerList
				LMarkerList.reRenderData();
			});
		});
	},
	
	setYearCode:function($span, code){
		$span.attr('data-spm-anchor-id', code);
	},
	
	getYearCode:function(){
		var $span =$("em.cl-year>span").first();
		return $span.attr('data-spm-anchor-id');
	}
};

var permitActualController = {
		
	initial: function(){
		//$("em.cl-air>span").first().text('空气指标');
		
		$("#myButton2").click(function(){
			ConditionController.hideConditionList();
		});
	},
	
	render: function(data) {
		for(var i=0; i<data.length; i++) {
			$("#permitAcutalPolluteCode").append("<option value='"+data[i].polluteCode+"'>"+data[i].polluteName+"</option >");
		}
		permitActualController.onSelect();
	},
	
	onMove: function() {
		
	},
	
	onSelect: function() {
		
		$('#permitAcutalPolluteCode').change(function(){
			
		});
	}
};

var AirController = {
		
	initial: function(){
		$("em.cl-air>span").first().text('空气指标');
		
		AirController.render();
	},
	
	render: function(){
		var html = 	'<ul class="classify-sort-type">'+
						'<li id="cl-0" class="sort-select">'+
							'<span class="cl-area-name">'+
								'SO2'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
						'</li>'+
						'<li id="cl-0" class="">'+
							'<span class="cl-area-name">'+
								'NO2'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
						'</li>'+
						'<li id="cl-1" class="">'+
							'<span class="cl-area-name">'+
								'CO'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
						'</li>'+
						'<li id="cl-0" class="sort-select">'+
							'<span class="cl-area-name">'+
								'O3'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
						'</li>'+
						'<li id="cl-0" class="">'+
							'<span class="cl-area-name">'+
								'PM2.5'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
						'</li>'+
						'<li id="cl-1" class="">'+
							'<span class="cl-area-name">'+
								'PM10'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
						'</li>'+
						'<li id="cl-1" class="">'+
							'<span class="cl-area-name">'+
								'综指'+
							'</span>'+
							'<span class="cl-right-arrow">'+
							'</span>'+
						'</li>'+
					'</ul>';
	
		$("#air").html(html); 
		$('#air ul.classify-sort-type li').first().addClass('sort-select');
		
		AirController.onMove();
		AirController.onSelect();
	},
	
	onMove: function() {
		$('#air ul.classify-sort-type li').each(function(){
			$(this).mouseover(function(){
				$('ul.classify-sort-type li').removeClass('sort-select');
				$(this).addClass('sort-select');
			});
		});
	},
	
	onSelect: function() {
		$('#air ul.classify-sort-type li').each(function(){
			$(this).click(function(){
				$("em.cl-air>span").first().text($(this).text());
				$('#air ul.classify-sort-type li').removeClass('sort-select');
				$(this).addClass('sort-select');
				$(".classsify-down").css({"display":"none"});
			});
		});
	}
};

var PanelController = {
	
	initial: function(){
		PanelController.hidePanel();
	},
	
	showPanel: function(){
		$("#panel").css({"display":"block"});
	},
	
	hidePanel: function(){
		$("#panel").css({"display":"none"});
	}
};